<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Google Maps JavaScript API Example: 	Reverse Geocoder</title>
    <script src="http://ditu.google.com/maps?hl=zh-CN&amp;file=api&amp;v=2&amp;key=ABQIAAAA91OZMiOe8VfhdtstxQrBBxQMwdEejL6PNWQ60w7dBVYMUBtoYxSzpO8QrLyX6KzYJkpyIz3Q53terg"></script>
    <script type="text/javascript">

    var map;
    var geocoder;
    var address;

//    var response = {
//        "name": "116.439972,39.998164",
//        "Status": {
//            "code": 200,
//            "request": "geocode"
//        
//        },
//        "Placemark": [{
//            "id": "p1",
//            "address": "China, Beijing朝阳区",
//            "AddressDetails": {
//                "Country": {
//                    "CountryNameCode": "CN",
//                    "CountryName": "China",
//                    "Locality": {
//                        "LocalityName": "Beijing",
//                        "DependentLocality": {
//                            "DependentLocalityName": "朝阳区"
//                        }
//                    }
//                },
//                "Accuracy": 4
//            },
//            "Point": {
//                "coordinates": [116.497725, 39.952747, 0]
//            }
//        }]
//    };

    function initialize() {
      if (GBrowserIsCompatible()) {
      var options = {
       listingTypes : "kmlonly"
      };
 
       map = new GMap2(document.getElementById("map_canvas"), {size:new GSize(400, 300)});
       map.setCenter(new GLatLng(39.917, 116.397), 14);
       map.addControl(new GSmallMapControl());
       GEvent.addListener(map, "click", getAddress);
       geocoder = new GClientGeocoder();
//       map.enableGoogleBar();
      }
    }
    
    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }

    function showAddress(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("嗯，你点击的这个地方还没有准确地址！"+"状态码（Status Code）:" + response.Status.code);
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(
        '<div style="font-size:13px;">' +
        '<b>你现在所点击的地址:</b><br/>' + place.address + '<br/><br/>' +
        '<b>准确度:</b>' + place.AddressDetails.Accuracy + '&nbsp;&nbsp;&nbsp;&nbsp;' +
        '<b>国家代码:</b> ' + place.AddressDetails.Country.CountryNameCode) +
        '</div>';
      }
    }


    </script>
   </head>
   <body onload="initialize()">
    <div id="map_canvas"></div>
  </body></html>